<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>系统用户设置</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<%@include file="common.jsp"%>
</head>
<body>
	<div style="margin-top:20px;">
		<button onclick="addUserInfo()" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#addUserInfoBox">新增</button>
		<button onclick="delUserInfo()" class="btn btn-primary btn-lg">删除</button>
	</div>
	<div style="margin-top:-10px;">
		<table id="userInfoTable" class="text-nowrap"></table>
	</div>
	<!-- 新增银行产品信息窗口 -->
	<div class="modal fade" id="addUserInfoBox" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabel">新增系统用户</h4>
                <h4 class="modal-title" id="myModalLabel2">修改系统用户</h4>
            </div>
            <div class="modal-body">
           		 <form id="userInfoForm" method='post' class="form-inline" enctype="multipart/form-data">
				 	<div class="form-group">
				    	<label for="exampleInputName2">用户帐号：</label>
				    	<input id="userCode" name="userCode" class="form-control"/>
				    	<input id="id" name="id" hidden="ture"/>
				  	</div>
				  	<div class="form-group" style="margin-left:20px;">
				    	<label for="exampleInputEmail2">用户名称：</label>
				    	<input id="userName" name="userName" class="form-control"/>
				  	</div>
				  	<div class="form-group" style="margin-top:20px;">
				  		<label for="exampleInputEmail2">用户密码：</label>
				  		<input id="passWord" name="passWord" class="form-control" />
				  	</div>
				  	<div class="form-group" style="margin-left:20px;margin-top:20px;">
				  		<label for="exampleInputEmail2">用户类别：</label>
				  		<select id="userType" name="userType" class="form-control" style="padding: 0 10px 0 0;">
				  			<option value="1">管理员</option>
				  			<option value="2">客服</option>
				  		</select>
				  	</div>
				</form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary" id="addUserInfo" onclick="submitUserInfo()">提交</button>
                <button type="button" class="btn btn-primary" id="updateUserInfo" onclick="updateUserInfo()">修改</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
	</div>
</body>
<script type="text/javascript">
//重载表格
$(function(){
	//加载表格
	$("#userInfoTable").bootstrapTable({
		url: "${pageContext.request.contextPath}/userInfo/findUserInfo.do",
		method: "post",
		cache: false,
		dataType: "json",
		contentType: "application/x-www-form-urlencoded",
		toolbar: "#toolbar",
		classes: "table table-hover table-striped",
		height:450,
		pagination: true,
		sidePagination: 'server',
		search: false,
		smartDisplay:false,
		sortOrder: "desc",
		searchText: "",
		showRefresh: false,
		showToggle: false,
		singleSelect: true,
		showPaginationSwitch: false,
		pageNumber: 1,
		pageSize: 5,
		pageList: [5, 10, 20, 40],
		clickToSelect: true,
		onCheck: function (row) {
		},
		queryParamsType: "undefined",
		queryParams: function (params) {
			var params = {
				pageNum: params.pageNumber,
				pageSize: params.pageSize,
				sortBy: params.sortOrder,
			}
			return params;
		},
		columns: [
			{ checkbox: true }
			,{
				field: "userCode",
				title: "帐号"
			}, {
				field: "userName",
				title: "名称"
			}, {
				field: "passWord",
				title: "密码"
			}, {
				field: "userType",
				title: "类型",
				formatter:function(value, row, index){
					if(value == 1){
						return "管理员";
					}else{
						return "客服";
					}
				}
			}
			
		],
		responseHandler: function (data) {//onLoad前处理数据源
			return data;
		},
		onLoadSuccess: function (data) {	//成功时执行
		},
		onLoadError: function (data) {	//失败时执行
			return;
		},
		//双击行事件
		onDblClickRow:function(row){
			//清空表单
			document.getElementById("userInfoForm").reset();
			//弹出框标题
			$('#myModalLabel').hide();
			$('#myModalLabel2').show();
			//按钮
			$('#addUserInfo').hide();
			$('#updateUserInfo').show();
			
			//控件赋值
			$('#userCode').val(row.userCode);
			$('#userName').val(row.userName);
			$('#passWord').val(row.passWord);
			$('#userType').val(row.userType);
			$('#id').val(row.id);
			//打开弹出框
			$('#addUserInfoBox').modal('show');
		}
	});
})
/**
 * 新增系统用户
 */
function addUserInfo(){
	//清空表单
	document.getElementById("userInfoForm").reset();
	//弹出框标题
	$('#myModalLabel2').hide();
	$('#myModalLabel').show();
	//按钮
	$('#updateUserInfo').hide();
	$('#addUserInfo').show();
}
/**
 * 新增系统用户
 */
function submitUserInfo(){
	var submitData = new FormData(document.getElementById("userInfoForm"));
	$.ajax({
		url: "${pageContext.request.contextPath}/userInfo/addUserInfo.do",
		data: submitData,
		type: "post",
		processData: false,
		contentType:false,
		success:function(data){
			alert(data);
			//刷新表格数据
			$('#userInfoTable').bootstrapTable('refresh');
			//隐藏模态框
			$('#addUserInfoBox').modal('hide');
		}
	})
}
/**
 * 修改系统用户
 */
function updateUserInfo(){
	if(confirm("确认修改？")){
		var submitData = new FormData(document.getElementById("userInfoForm"));
		$.ajax({
			url: "${pageContext.request.contextPath}/userInfo/updateUserInfo.do",
			data: submitData,
			type: "post",
			processData: false,
			contentType:false,
			success:function(data){
				alert(data);
				//刷新表格数据
				$('#userInfoTable').bootstrapTable('refresh');
				//隐藏模态框
				$('#addUserInfoBox').modal('hide');
			}
		})
	}
}
function delUserInfo(){
	var rows = $('#userInfoTable').bootstrapTable('getSelections');
	if(rows.length <= 0){
		return alert("请选择数据！");
	}
	if(confirm("确认删除？")){
		//from对象序列化
		//var data = $('#bankForm').serialize();
		//var submitData = decodeURIComponent(data,true);
		var row = rows[0];
		$.ajax({
			url:"${pageContext.request.contextPath}/userInfo/delUserInfo.do",
			data: {
				id:row.id
			},
			type:"post",
			dataType:"json",
			processData: true,
			success:function(data){
				alert(data);
				//刷新表格数据
				$('#userInfoTable').bootstrapTable('refresh');
			}
		})
	}
}
</script>
</html>




